<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="p" uri="/WEB-INF/tld/pagination.tld"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户管理信息</title>
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath}/css/public.css">
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/js/sorttable.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/public.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/validate.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/baseset.js"></script>
		<script language="JavaScript"
			src="${pageContext.request.contextPath}/js/checkboxSelect.js"></script>

		<script type="text/javascript">
		//验证输入数据合法性
	  	function validate(){		  	
			var username = document.getElementById("username");
			var rolename = document.getElementById("rolename");
					
			if(!f_check_ZhOrNumOrLett(username,'用户名'))
				return false;	
			 if(!f_check_ZhOrNumOrLett(rolename,'用户组'))
				return false;	
		} 
		
		//修改用户和用户组
		function editUserAndRole(){
			var userIDs = document.getElementsByName("userId");
			var roleIDs = document.getElementsByName("roleId");
			var editID="";
			var formname = document.getElementById("editUserAndRoleForm");//formd的ID

			var userIDCount = 0;
			var roleIDCount = 0;
	
			for (var i = 0; i < userIDs.length; i++) {
				if (userIDs[i].checked) {
					userIDCount++;
					editID = editID+userIDs[i].value+",";
				}
			}
	
			for (var i = 0; i < roleIDs.length; i++) {	
				if (roleIDs[i].checked) {
					roleIDCount++;
					editID = editID+roleIDs[i].value+",";
				}
			}

			var sum = userIDCount+roleIDCount;
			if (sum<1) {
				alert("您还没有进行选择！");
				return false;
			} 
			var array = editID.split(",");	
	 		if (sum >1) {
				alert("每次修改用户或用户组只能选择两者中一条记录！");
				return false;
			} else {
				if (userIDCount == 1) {
					if (confirm("确认要修改该记录吗？")) {
						formname.action = "showEditUser.action?editUserID="+array[0];
						formname.submit();
					}
				}
				if (roleIDCount == 1) {
					if (confirm("确认要修改该记录吗？")) {
						formname.action = "showEditUserGroup.action?editUserGroupID="+array[0];	
						formname.submit();
					}
				}	
			} 	
		}
		
		//删除用户和用户组
		function deleteUserAndRole(){
			var userIDs = document.getElementsByName("userId");
			var roleIDs = document.getElementsByName("roleId");
			var deletedUserID="";
			var deletedRoleID="";
			var formname = document.getElementById("editUserAndRoleForm");//formd的ID

			var userIDCount = 0;
			var roleIDCount = 0;
	
			for (var i = 0; i < userIDs.length; i++) {
				if (userIDs[i].checked) {
					userIDCount++;
					deletedUserID = deletedUserID+userIDs[i].value+",";
				}
			}
	
			for (var i = 0; i < roleIDs.length; i++) {	
				if (roleIDs[i].checked) {
					roleIDCount++;
					deletedRoleID = deletedRoleID+roleIDs[i].value+",";
				}
			}

			var sum = userIDCount+roleIDCount;
			if (sum<1) {
				alert("您还没有进行选择！");
				return false;
			} 
			
			if (confirm("确认要删除记录吗？")) {
				// alert("deleteUser.action?deletedUserID="+deletedUserID+"&deletedRoleID="+deletedRoleID);
				formname.action = "deleteUserAndRole.action?deletedUserID="+deletedUserID+"&deletedRoleID="+deletedRoleID;
				formname.submit();
			}
		}
		
		function getUserAndRole(){	
			var formname = document.getElementById("editUserAndRoleForm");//form的ID

			formname.username.value = trimSpecialCharacter(trimSpaces(formname.username.value));
			// alert("username is:"+formname.username.value);
			formname.action = "getUserAndRole.action";
			formname.submit();
		}
		
		function showPurviewManage(){
		var userIDs = document.getElementsByName("userId");
			var roleIDs = document.getElementsByName("roleId");
			var editID="";
			var formname = document.getElementById("editUserAndRoleForm");//formd的ID

			var userIDCount = 0;
			var roleIDCount = 0;
	
			for (var i = 0; i < userIDs.length; i++) {
				if (userIDs[i].checked) {
					userIDCount++;
					editID = editID+userIDs[i].value+",";
				}
			}
	
			for (var i = 0; i < roleIDs.length; i++) {	
				if (roleIDs[i].checked) {
					roleIDCount++;
					editID = editID+roleIDs[i].value+",";
				}
			}

			var sum = userIDCount+roleIDCount;
			if (sum<1) {
				alert("您还没有进行选择！");
				return false;
			} 
			var array = editID.split(",");	
	 		if (sum >1) {
				alert("每次权限管理只能选择用户组中一条记录！");
				return false;
			} else {
				if (userIDCount == 1) {
					alert("请对该用户所属用户组进行管理！");
				return false;
				}
				if (roleIDCount == 1) {
					if (confirm("确认管理该用户组吗？")) {
						formname.action = "showEditUserPurview.action?editUserGroupID="+array[0];	
						formname.submit();
					}
				}	
			} 	
		}
		
		function showPurviewView(){
			var formname = document.getElementById("editUserAndRoleForm");//formd的ID
			formname.action = "showPurviewView.action";	
			formname.submit();
		}
		</script>
	</head>
	<body>
		<div id="info_all">
			<div id="info_top">
				用户管理
			</div>
			<!-- 主输入区 -->
			<!-- 功能按钮 -->
		
			<s:form name="editUserAndRoleForm" theme="simple" action="getUserAndRole.action"
				cssStyle="margin-top:0px" id="editUserAndRoleForm" >
				<div id="btn">
					<input type="button" value="新增用户" onClick="showAddUser()"
						onFocus="this.blur()" onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" class="btnsize" />
					<input type="button" value="新增用户组" onClick="showAddUserGroup()"
						onFocus="this.blur()" onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" class="btnsize" />
					<input type="button" value="删除" onClick="deleteUserAndRole()"
						onFocus="this.blur()" onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" class="btnsize" />
					<input type="button" value="修改" onClick="editUserAndRole()"
						class="btnsize" />
					<input type="button" value="权限管理" onClick="showPurviewManage()" onFocus="this.blur()"
						onmouseover="this.className='btnover'"
						onmouseout="this.className='btnout'" class="btnsize" />
					<input type="button" value="权限浏览"  onFocus="this.blur()"
						onmouseover="this.className='btnover'" onClick="showPurviewView()"
						onmouseout="this.className='btnout'" class="btnsize" />
				</div>

				<div id="info_main">
					<!-- 查询栏 -->			
						<div id="sele">
							<table>
								<tr>
									<td>
										用户名&nbsp;
									</td>
									<td>
										<input type="text" name="username" size="12" id="username">
										&nbsp;&nbsp;&nbsp;
									</td>
									<td>
										用户组&nbsp;
									</td>
									<td>
										<input type="text" name="rolename" size="12" id="rolename" />
									</td>
								</tr>
							</table>
						</div>
						<div class="sele">
							<input type="submit" value="查询" onFocus="this.blur()" onClick="return validate();"
								onmouseover="this.className='btnover'"
								onmouseout="this.className='btnout'" class="btnsize" />
							<input type="reset" value="重置" onFocus="this.blur()"
								onmouseover="this.className='btnover'"
								onmouseout="this.className='btnout'" class="btnsize" />
							<hr>
						</div>
					

					<!-- 信息显示栏 -->
					<div id="info_infoShort" style="margin-top: -5px;">
						<table id="info_table" width="220px" cellspacing=1px
								cellpadding=1px class="">
								<thead align="center">
									<tr>
										<th>
											<input type="checkbox" onClick="selectAll()" />
										</th>
										<th width="100px">
											用户名
										</th>
										<th width="100px">
											说明
										</th>
									</tr>
								</thead>
							</table>
						<div id="info_info_x" class="rollTable">
							<table id="info_table" width="220px" cellspacing=1px
								cellpadding=1px class="sortable">
								<tbody align="center">
									<s:iterator value="userList">
										<tr>
											<td>
												<input type="checkbox" name="userId" id="userId"
													value="${userId}" />
											</td>
											<td width="100px">
												<s:property value="userName" />

											</td>
											<td width="100px">
												<s:property value="userDesc" />
											</td>
										</tr>
									</s:iterator>
								</tbody>
								<tfoot>
								</tfoot>
							</table>
							<s:if test="!userList.isEmpty">
							<tr style="font-size: 12px;">
								<div align="center">
									<font color="#FF0000"> 共<s:property value="page.total" />
										页 第 <s:property value="page.cpage" /> 页 <p:page
											cpage="%{page.cpage}" total="%{page.total}" url="%{page.url}" />
									</font>

								</div>
							</tr>
							</s:if>
						</div>
						<hr>
						<table id="info_table2" width="220px" cellspacing=1px
								cellpadding=1px class="">
								<thead align="center">
									<tr>
										<th>
											<input type="checkbox" onClick="selectAllTwo()" />
										</th>
										<th width="100px">
											用户组
										</th>
										<th width="100px">
											说明
										</th>
									</tr>
								</thead>
							</table>
						<div id="info_info_y" class="rollTable">
							<table id="info_table2" width="220px" cellspacing=1px
								cellpadding=1px class="sortable">
								<tbody align="center">
									<s:iterator value="userGroupList">
										<tr>
											<td>
												<input type="checkbox" name="roleId" id="roleId"
													value="${roleId}" />
											</td>
											<td width="100px">
												<s:property value="roleName" />

											</td>

											<td width="100px">
												<s:property value="roleDesc" />
											</td>
										</tr>
									</s:iterator>
								</tbody>
								<tfoot>
								</tfoot>
							</table>
							
						</div>
						<script language="javascript">  
						//("表格名称","奇数行背景","偶数行背景","点击后背景");
						 mouseclick("info_table","#ffffff","#ffffff","#e6f0fd");
						 mouseclick("info_table2","#ffffff","#ffffff","#e6f0fd");
						 //("表格名称","奇数行背景","偶数行背景");
						 //setcolor("t","#ffffff","#ffffff");
						</script>

					</div>

				</div>
				</s:form>
			
		</div>
	</body>
</html>